﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace B.S.BasicData.Infrastcuture.Commons
{
    /// <summary>
    /// 枚举扩展
    /// </summary>
    public static class EnumExtension
    {
        /// <summary>
        /// 枚举特性
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>返回任务</returns>
        public static string Description(this Enum value)
        {
            FieldInfo field = value.GetType().GetField(value.ToString());
            DescriptionAttribute attribute=field.GetCustomAttribute<DescriptionAttribute>();
            return attribute==null?value.ToString() : attribute.Description;
        }
    }
}
